#include<bits/stdc++.h>
using namespace std;
const int N=200003;
int a[N],s[N],f[N],f1[N],n;
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T; cin>>T; T=6;
    while(T--){
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
            if(a[i]!=a[i-1]) s[i]=s[i-1];
            else s[i]=s[i-1]+a[i];
        }
        for(int i=1;i<=n;i++){
            f[i]=f[i-1],f1[i]=0;
            if(a[i]==a[i-1]) f[i]+=a[i];
            for(int j=1;j<i-1;j++){
                if(a[j]!=a[i]) continue;
                f1[i]=max(f1[i],max(f1[j+1],f[j])+s[i-1]-s[j+1]+a[i]);
            }
            f[i]=max(f[i],f1[i]);
        }
        cout<<f[n]<<endl;
    }
    return 0;
}
